# coding: utf-8

from rest_framework import serializers

from usercenter.common.regex import (
    RE_PHONE,
    RE_ID_CARD,
    RE_TELEPHONE,
    RE_DOMAIN,
    RE_MOBILEPHONE,
    RE_EMAIL,
)


def error_phone(phone):
    return False if RE_PHONE.match(phone) else True


def error_id_card(id_card):
    return False if RE_ID_CARD.match(id_card) else True


def error_telephone(telephone):
    return False if RE_TELEPHONE.match(telephone) else True


def error_mobilephone(mobilephone):
    return False if RE_MOBILEPHONE.match(mobilephone) else True


def error_domain(domain):
    return False if RE_DOMAIN.match(domain) else True


def error_email(email):
    return False if RE_EMAIL.match(email) else True


def validate_phone(phone):
    '''
    '电话是否有误
    :param phone:
    :return:
    '''
    return not error_phone(phone)


def validate_domain(domain):
    '''
    '是否正确的域名
    :param domain:
    :return:
    '''
    return not error_domain(domain)


def validate_id_card(id_card):
    '''
    '身份证号是否有误
    :param id_card:
    :return:
    '''
    return not error_id_card(id_card)


def validate_telephone(telephone):
    '''
    '座机是否有误
    :param telephone:
    :return:
    '''
    return not error_telephone(telephone)


def validate_mobilephone(mobilephone):
    '''
    '手机是否有误
    :param mobilephone:
    :return:
    '''
    return not error_mobilephone(mobilephone)


def validate_regnumber(regnumber):
    '''
    营业执照注册号必须是15位或者18位
    :param regnumber:
    :return:
    '''
    return len(regnumber) not in (15, 18)


def validate_email(email):
    '''
    '邮箱是否有误
    :param email:
    :return:
    '''
    return not error_email(email)
